class Solution {
    public:
        int is_existent[50][50] ={0};
        int scolor;
        vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
            is_existent[sr][sc] = 1;
            scolor = image[sr][sc];
            image[sr][sc] = color;
            dfs(image,sr,sc,color);
            return image;
        }
        int indexx[4] = {0,0,1,-1};
        int indexy[4] = {1,-1,0,0};
        void dfs(vector<vector<int>>& image, int i, int j, int color){
            int n = image.size(),m = image[0].size();
            for(int k = 0 ; k < 4 ; k++){
                int row = i+indexx[k];
                int col = j+indexy[k];
                if(row >= 0 && row < n && col >=0 &&col <m && image[row][col] == scolor && is_existent[row][col] == 0){
                    cout<<row<<" "<<col<<endl;
                    is_existent[row][col] = 1;
                    image[row][col] = color;
                    dfs(image,row,col,color);
                    // is_existent[row][col] = 0;
                    // image[row][col] = scolor;  图像渲染回溯时不需要更改
                }
            }
            return;
        }
    
    };